// components/like/index.js
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    like:{
      type:Boolean,
      value:false,
      observer(){}
    },
    count: {
      type: Number,
      value: 10,
      observer(){}
    },
    readOnly:{
      type:Boolean
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    yesSrc:'imager/like.png',
    noSrc:'imager/like@dis.png'
  },

  /**
   * 组件的方法列表
   */
  methods: {
    onLike(event){
      //自定义事件
      if (this.properties.readOnly){
        return
      }
      let like=this.properties.like
      let count = this.properties.count
      
      count = like ? count - 1 : count + 1
      this.setData({
        count:count,
        like:!like
      })
      //激活点赞
      let behavior = this.properties.like? "like":"cancel"
      //如何激活一个事件 事件的名称》用户传参》是否冒泡
      this.triggerEvent("like", { behavior: behavior},{})
    }
  }
})
